<?php
/**
 * AclPersistence
 *
 * @category	acl
 * @package		dayscript.acl.persistence
 * @subpackage
 * @author		Noel Marin <nmarin@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license
 * @version		1.0
 * @version		$Revision: 0 $
 * @filesource
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses
 * @since		1.0
 * @modifiedby	$LastChangedBy: Noel Marin $
 * @modified	$Date: 2009-09-24 $
 */
namespace dayscript\acl\persistence;

/**
 * AclPersistence
 * 
 * Persistence generic class for ACLs
 *
 * @category	acl
 * @package		dayscript.acl.persistence
 * @subpackage
 * @author		Noel Marin <nmarin@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license
 * @version		1.0
 * @version		$Revision: 0 $
 * @filesource
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		\dayscript\acl\Acl \dayscript\datasource\DataSource
 * @since		1.0
 * @modifiedby	$LastChangedBy: Noel Marin $
 * @modified	$Date: 2009-09-24 $
 */
abstract class AclPersistence {
	
	/**
	 * Persisted ACL
	 * 
	 * @var \dayscript\acl\Acl
	 */
	protected $acl; 
	
	/**
	 * Implemented datasource object
	 * 
	 * @var \dayscript\datasource\DataSource
	 */
	protected $dataSource;
	
	/**
	 * Create datasource structure for persisting acl
	 * 
	 * @return boolean Success or not
	 */
	public abstract function init();
	
	/**
	 * Saved the acl using the specified datasource
	 * 
	 * @return boolean Success or not
	 */
	public abstract function commit(\dayscript\acl\Acl $acl);
	
	/**
	 * Load the acl from the specified datasource
	 * 
	 * 
	 * @param $rol \dayscript\acl\role\Role|array|null Load the rol's acl if parameter is not null, if it's null load complete acl
	 * @return \dayscript\acl\Acl
	 */
	public abstract function load($rol = null);

	/**
	 * Return the persisted ACL
	 * 
	 * @return \dayscript\acl\Acl
	 */
	public function getAcl(){
		return $this->acl;
	}
	
	/**
	 * Sets the persisted ACL
	 * 
	 * @param $acl \dayscript\acl\Acl
	 * @return void
	 */
	public function setAcl(\dayscript\acl\Acl $acl){
		$this->acl = $acl;
	}
	
	/**
	 * Return the datasource
	 * 
	 * @return \dayscript\datasource\DataSource
	 */
	public function getDataSource(){
		return $this->acl;
	}
	
	/**
	 * Sets the datasource
	 * 
	 * @param $dataSource \dayscript\datasource\DataSource
	 * @return void
	 */
	public function setDataSource(\dayscript\datasource\DataSource $dataSource){
		$this->dataSource = $dataSource;
	}
}